import re
import requests
import bs4
from bs4 import BeautifulSoup

cookies = {
    'PHPSESSID': 'nlpb2mr6gtgncsi9dve479q9p5',
    'ex': '1',
    'Hm_lvt_d944abe74d06c6f8e0875fdc2b67fa90': '1593682745',
    'Hm_lpvt_d944abe74d06c6f8e0875fdc2b67fa90': '1593699817',
}

headers = {
    'Connection': 'keep-alive',
    'Cache-Control': 'max-age=0',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',    
    'Accept-Language': 'zh-CN,zh;q=0.9',
}

response = requests.get('http://cilibao.biz/detail/4738d2dd8926a4413865b24f67080631cb7a29f9.html', headers=headers, cookies=cookies, verify=False)

soup = BeautifulSoup(response.text,'html.parser')
def parse_one_page(ulist, html):
    # 获取视频连接列表
    soup = BeautifulSoup(html, 'html.parser')
    for tr in soup.find_all('a', re.compile('fr')):
        if isinstance(tr, bs4.element.Tag):
            if tr.get('data-url'):
                ulist.append(tr.get('data-url')+'\n')

def myParser(url_response):
    soup = BeautifulSoup(url_response, 'html.parser')
    print("soup")
    for title in soup.find_all('h1', re.compile('res-title')):
        # get titles.
        if isinstance(title, bs4.element.Tag):
            print(title.string)
    # 有多个满足条件的,定位不准确，只取第一个.
    # 也可以使用正则表达式.
    magnet_url = soup.find_all('a', 'download')[0]    
    if isinstance(magnet_url, bs4.element.Tag):
        print(magnet_url.get('href'))
        
myParser(response.text)